Python/Python Mcq Set 21 Sample Test,Sample questions

Question:
 What will be the output of the following Python code?

def a():
    try:
        f(x, 4)
    finally:
        print('after f')
    print('after f?')
a()

1.No output

2. after f?

3.error

4.after f

Posted Date:-2022-01-02 12:27:10


Question:
An exception is _______

1. an object

2.a special function

3. a standard module

4. a module

Posted Date:-2022-01-02 12:35:26


Question:
Compare the following two Python codes shown below and state the output if the input entered in each case is -6?

CODE 1
import math
num=int(input("Enter a number of whose factorial you want to find"))
print(math.factorial(num))
 
CODE 2
num=int(input("Enter a number of whose factorial you want to find"))
print(math.factorial(num))

1. ValueError, NameError

2.AttributeError, ValueError

3.NameError, TypeError

4.TypeError, ValueError

Posted Date:-2022-01-02 12:32:09


Question:
Identify the type of error in the following Python codes?

Print(“Good Morning”)
print(“Good night)

1.Syntax, Syntax

2.Semantic, Syntax

3. Semantic, Semantic

4.Syntax, Semantic

Posted Date:-2022-01-02 12:33:54


Question:
The error displayed in the following Python code is?

import itertools
l1=(1, 2, 3)
l2=[4, 5, 6]
l=itertools.chain(l1, l2)
print(next(l1))

1.‘list’ object is not iterator

2.‘tuple’ object is not iterator

3. ‘list’ object is iterator

4. ‘tuple’ object is iterator

Posted Date:-2022-01-02 12:28:11


Question:
What happens if the file is not found in the following Python code?

a=False
while not a:
    try:
        f_n = input("Enter file name")
        i_f = open(f_n, 'r')
    except:
        print("Input file not found")

1.No error

2.Assertion error

3.Input output error

4. Name error

Posted Date:-2022-01-02 12:29:48


Question:
What will be the output of the following Python code if the input entered is 6?

valid = False
while not valid:
    try:
        n=int(input("Enter a number"))
        while n%2==0:
            print("Bye")
        valid = True
    except ValueError:
        print("Invalid")

1.Bye (printed once)

2.No output

3.Invalid (printed once)

4.Bye (printed infinite number of times)

Posted Date:-2022-01-02 12:32:59


Question:
What will be the output of the following Python code, if the time module has already been imported?

4 + '3'

1.NameError

2. IndexError

3. ValueError

4. TypeError

Posted Date:-2022-01-02 12:31:02


Question:
What will be the output of the following Python code?

#generator
def f(x):
    yield x+1
g=f(8)
print(next(g))

1.8

2.9

3.7

4.Error

Posted Date:-2022-01-02 12:25:22


Question:
What will be the output of the following Python code?

def f(x):
    for i in range(5):
        yield i
g=f(8)
print(list(g))

1. [0, 1, 2, 3, 4]

2.[1, 2, 3, 4, 5, 6, 7, 8]

3. [1, 2, 3, 4, 5]

4. [0, 1, 2, 3, 4, 5, 6, 7]

Posted Date:-2022-01-02 12:27:43


Question:
What will be the output of the following Python code?

def f(x):
    yield x+1
    print("test")
    yield x+2
g=f(9)

1. Error

2. test

3.test 10 12

4.No output

Posted Date:-2022-01-02 12:26:24


Question:
What will be the output of the following Python code?

def getMonth(m):
    if m<1 or m>12:
        raise ValueError("Invalid")
    print(m)
getMonth(6)

1. ValueError

2. Invalid

3.6

4.ValueError(“Invalid”)

Posted Date:-2022-01-02 12:32:33


Question:
What will be the output of the following Python code?

g = (i for i in range(5))
type(g)

1.class <’loop’>

2.class <‘iteration’>

3.class <’range’>

4.class <’generator’>

Posted Date:-2022-01-02 12:29:09


Question:
What will be the output of the following Python code?

int('65.43')

1. ImportError

2.ValueError

3.TypeError

4.NameError

Posted Date:-2022-01-02 12:31:35


Question:
What will be the output of the following Python code?

lst = [1, 2, 3]
lst[3]

1.NameError

2.ValueError

3. IndexError

4. TypeError

Posted Date:-2022-01-02 12:30:12


Question:
What will be the output of the following Python code?

t[5]

1.IndexError

2. NameError

3.TypeError

4.ValeError

Posted Date:-2022-01-02 12:30:36


Question:
Which of the following blocks will be executed whether an exception is thrown or not?

1. except

2.else

3.finally

4. assert

Posted Date:-2022-01-02 12:37:09


Question:
Which of the following is not a standard exception in Python?

1.NameError

2.IOError

3.AssignmentError

4.ValueError(“Invalid”)

Posted Date:-2022-01-02 12:34:58


Question:
Which of the following is not an exception handling keyword in Python?

1. try

2.except

3.accept

4.finally

Posted Date:-2022-01-02 12:28:38


Question:
Which of the following statements is true?

1.The standard exceptions are automatically imported into Python programs

2.All raised standard exceptions must be handled in Python

3.When there is a deviation from the rules of a programming language, a semantic error is thrown

4.If any exception is thrown in try block, else block is executed

Posted Date:-2022-01-02 12:34:24


Question:
_______________ exceptions are raised as a result of an error in opening a particular file.

1.ValueError

2.TypeError

3. ImportError

4.IOError

Posted Date:-2022-01-02 12:35:48


More MCQS

  1. Python MCQS - Function
  2. Python MCQS - GUI in python
  3. Python MCQS - Operators
  4. Python MCQS - Data type in python
  5. Python MCQS - loops in python
  6. Python MCQS - Numpy
  7. Python MCQS - sqlite3
  8. Python MCQS - Library
  9. Python MCQS - Pandas
  10. Python MCQs
  11. Dictionary Python MCQ set 1
  12. Dictionary Python MCQ set 2
  13. MCQ For Python Fundamentals
  14. MCQ Introduction to Python Section 1
  15. MCQ Introduction to Python Section 2
  16. MCQ Introduction to Python Section 3
  17. MCQ on Flow of Control in Python Set 1
  18. MCQ on Flow of Control in Python Set 2
  19. MCQ on Python String Set 1
  20. File Handling in Python section 1
  21. File Handling in Python section 2
  22. Python Functions MCQS Set 1
  23. Python Functions MCQS Set 2
  24. MCQ on List in Python
  25. Pandas MCQ Questions Set 1
  26. Pandas MCQ Questions Set 2
  27. Tuple MCQ in Python
  28. Python dataframe MCQ
  29. Python Mcq Set 1
  30. Python Mcq Set 2
  31. Python Mcq Set 3
  32. Python Mcq Set 4
  33. Python Mcq Set 5
  34. Python Mcq Set 6
  35. Python Mcq Set 7
  36. Python Mcq Set 8
  37. Python Mcq Set 9
  38. Python Mcq Set 10
  39. Python Mcq Set 11
  40. Python Mcq Set 12
  41. Python Mcq Set 13
  42. Python Mcq Set 14
  43. Python Mcq Set 15
  44. Python Mcq Set 16
  45. Python Mcq Set 17
  46. Python Mcq Set 18
  47. Python Mcq Set 19
  48. Python Mcq Set 20
  49. Python Mcq Set 21
  50. Python MCQ
  51. Python MCQ Questions with Answer
  52. Test
  53. python mcq question and answer
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!